﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FantomNext.Shared
{
    public struct Vector2
    {
        public readonly float X;
        public readonly float Y;

        public Vector2(float x, float y)
        {
            X = x;
            Y = y;
        }
        public Vector2(double x, double y)
        {
            X = (float)x;
            Y = (float)y;
        }

        // 重载加法运算符
        public static Vector2 operator +(Vector2 v1, Vector2 v2)
        {
            return new Vector2(v1.X + v2.X, v1.Y + v2.Y);
        }

        // 重载减法运算符
        public static Vector2 operator -(Vector2 v1, Vector2 v2)
        {
            return new Vector2(v1.X - v2.X, v1.Y - v2.Y);
        }

        // 重载负号运算符
        public static Vector2 operator -(Vector2 v)
        {
            return new Vector2(-v.X, -v.Y);
        }

        // 重载乘法运算符（向量与标量相乘）
        public static Vector2 operator *(Vector2 v, float scalar)
        {
            return new Vector2(v.X * scalar, v.Y * scalar);
        }

        // 重载乘法运算符（标量与向量相乘）
        public static Vector2 operator *(float scalar, Vector2 v)
        {
            return v * scalar;
        }

        // 重载除法运算符（向量除以标量）
        public static Vector2 operator /(Vector2 v, float scalar)
        {
            if (scalar == 0)
            {
                throw new DivideByZeroException("Cannot divide a vector by zero.");
            }
            return new Vector2(v.X / scalar, v.Y / scalar);
        }


        public static bool operator ==(Vector2 v1, Vector2 v2)
        {
            return v1.X == v2.X && v1.Y == v2.Y;
        }

        public static bool operator !=(Vector2 v1, Vector2 v2)
        {
            return v1.X != v2.X || v1.Y != v2.Y;
        }

        // 重写 ToString 方法
        public override string ToString()
        {
            return $"({X}, {Y})";
        }
    }
}
